

package com.hazelcast.internal.util.phonehome;

import com.hazelcast.instance.impl.Node;

import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;

import static com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.*;

class OSInfoProvider implements MetricsProvider {

    @Override
    public void provideMetrics(Node node, MetricsCollectionContext context) {
        OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
        try {
            context.collect(OPERATING_SYSTEM_NAME, osMxBean.getName());
            context.collect(OPERATING_SYSTEM_ARCH, osMxBean.getArch());
            context.collect(OPERATING_SYSTEM_VERSION, osMxBean.getVersion());
        } catch (SecurityException e) {
            context.collect(OPERATING_SYSTEM_NAME, "N/A");
            context.collect(OPERATING_SYSTEM_ARCH, "N/A");
            context.collect(OPERATING_SYSTEM_VERSION, "N/A");
        }
    }
}
